using QFramework;
using M13.Base;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace M13.Game.UI
{
    public class MainMenuUI : MonoBehaviour, IController, ICanSendEvent//��֣�9
    {
       // public List<GameObject> savePageLists = new List<GameObject>();

        //���˵�����ؼ�
        [Header("���˵�����ؼ�")]
        [SerializeField] private GameObject mainMenu;
        [SerializeField] private Button startButton;
        [SerializeField] private Button optionButton;
        [SerializeField] private Button exitButton;

        //�浵�б�����ؼ�
        [Header("�浵�б�����ؼ�")]
        [SerializeField] private GameObject saveListMenu;
        [SerializeField] private InputField searchBox;
        [SerializeField] private GameObject saveLists;
        [SerializeField] private Button intoWorldCreationMenuButton;
        [SerializeField] private Button exitFromSaveMenuButton;
        [SerializeField] private Button refrushSaveListButton;

        [SerializeField] private GameObject requestBox;
        [SerializeField] private Button requestConfirmBtn;
        [SerializeField] private Button requestCancelBtn;

        [Header("�����������ò˵�����ؼ�")]
        [SerializeField] private GameObject createWorldMenu;
        [SerializeField] private InputField saveNameInputField;
        [SerializeField] private InputField worldSeedinputField;
        [SerializeField] private Button createWorldButton;
        [SerializeField] private Button exitToSaveListsMenuButton;

        [Header("�浵�б�Ԥ����")]
        [SerializeField] private GameObject savePagePrefabs;

        [Header("�������ɽ���ҳ��")]
        [SerializeField] private GameObject worldCreateProgress;


        ConfirmDeleteSaveButton _confirmDeleteSaveButton;
        private void Start()
        {
            //��ʼ��Ϸ��ť��������¼�
            startButton.onClick.AddListener(() => this.SendEvent<StartGameButtonOfMainMenu>());
            //ѡ�ť��������¼�
            optionButton.onClick.AddListener(() => this.SendEvent<OptionButtonOfMainMenu>());
            //�˳���Ϸ��ť��������¼�
            exitButton.onClick.AddListener(() => this.SendEvent<ExitButtionOfMainMenu>());

            //�浵�б�ɸѡ�����ݸı��¼�
            searchBox.onValueChanged.AddListener((e) => this.SendEvent<SearchBoxValueChanged>());
            //�Ӵ浵�б�ҳ���˳������˵���ť����¼�
            exitFromSaveMenuButton.onClick.AddListener(() => this.SendEvent<ExitFromSaveMenuButton>());
            //ˢ�´浵�б���ť����¼�
            refrushSaveListButton.onClick.AddListener(() => this.SendEvent<RefreshSaveListsButton>());
            //�������紴���˵���ť����¼�
            intoWorldCreationMenuButton.onClick.AddListener(() => this.SendEvent<IntoWorldCreationMenuButton>());

            //ɾ���浵����ȷ����ť����¼�
            requestConfirmBtn.onClick.AddListener(() => this.SendEvent<ConfirmDeleteSaveButton>());
            //ɾ���浵����ȡ����ť����¼�
            requestCancelBtn.onClick.AddListener(() => this.SendEvent<CancelDeleteSaveButton>());

            //�Ӵ����¼��˵����ص��浵�б���ť����¼�
            exitToSaveListsMenuButton.onClick.AddListener(() => this.SendEvent<ExitFormWorldCreationMenuButton>());
            //�������簴ť����¼�
            createWorldButton.onClick.AddListener(()=>this.SendEvent<CreateNewSaveButton>());
            //��������ҳ�������������ݸı��¼�
            saveNameInputField.onValueChanged.AddListener((e) => this.SendEvent<SaveNameInputChanged>());
            //�����������ݸı��¼�
            worldSeedinputField.onValueChanged.AddListener((e) => this.SendEvent<SaveSeedInputChanged>());
        }

        /// <summary>
        /// �������˵��Ļ��
        /// </summary>
        /// <param name="b"></param>
        public void SetMainMenuActivity(bool b)
        {
            mainMenu.SetActive(b);
        }

        /// <summary>
        /// ���ô浵�б�ҳ��Ļ��
        /// </summary>
        /// <param name="b"></param>
        public void SetSaveListMenuActivity(bool b)
        {
            saveListMenu.SetActive(b);
        }

        /// <summary>
        /// ���ô����¼�ҳ��Ļ��
        /// </summary>
        /// <param name="b"></param>
        public void SetCreateWorldMenuActivity(bool b)
        {
            createWorldMenu.SetActive(b);
        }

        /// <summary>
        /// ����ɾ���浵ѯ�ʿ�Ļ��
        /// </summary>
        /// <param name="b"></param>
        public void SetSaveDeleteRequestBoxActivity(bool b)
        {
            requestBox.SetActive(b);
        }

        /// <summary>
        /// �����������ɽ���ҳ��Ļ��
        /// </summary>
        /// <param name="b"></param>
        public void SetWorldCreateProgressActivity(bool b)
        {
            worldCreateProgress.SetActive(b);

        }

        public InputField GetSaveSearchBox() { return searchBox; }
        public GameObject GetSaveListsParent() { return saveLists; }
        public InputField GetSaveNameInput() { return saveNameInputField; }
        public InputField GetSaveSeedInput() { return worldSeedinputField; }
        public GameObject AddNewSavePage()
        {
            GameObject savePage = Instantiate(savePagePrefabs);
            return savePage;
        }
        public GameObject GetDeleteRequestBox() { return requestBox; }
        public Button GetRequestConfirmBtn() { return requestConfirmBtn; }
        public Button GetRequestCancelBtn() { return requestCancelBtn; }
        public void ClearInput()
        {
            saveNameInputField.text = null;
            worldSeedinputField.text = null;
        }

        public IArchitecture GetArchitecture()
        {
            return GameArchitecture.Interface;
        }

    }
}